<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\GkyQyhAppSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Gky Qyh Apps';
$this->params['breadcrumbs'][] = $this->title;
?>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/common.js" type="text/javascript"></script>
<div class="gky-qyh-app-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div class="col-lg-12 col-md-12">
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
                ])
        ?>


        <div class="col-md-8 col-lg-8">
            <label style="float: left;margin-top: 5px;">应用名称</label>
            <div style="overflow: hidden;">
                <?php
                $datas = app\models\GkyQyhApp::find()->all();
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->name;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'name',
                    'options' => ['style' => 'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>     
            </div>
        </div>

        <div class="col-md-2 text-center">
            <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?> 
        </div>

        <div class="col-md-2 text-center">
            <?= Html::a('添加', ['create'], ['class' => 'btn btn-success']) ?>
        </div>

    </div>


    <div class="col-md-12 text-right" style="margin: 15px 0 15px 15px;">


    </div>

    <?php ActiveForm::end(); ?>    
    <?php Pjax::begin(); ?>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
//            ['class' => 'yii\grid\SerialColumn'],
//            'id',
            'name',
//            'report_location_flag',
//            'logo_mediaid',
//            'description',
            // 'redirect_domain',
            // 'isreportuser',
            // 'isreportenter',
            // 'qid',
            // 'addtime',
//            [
//                'class' => 'yii\grid\ActionColumn',
//                'template' => '{view} {update} {delete}',
//                'buttons' => [
//                    //view button
//                    'view' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>查看', $url, [
//                                    'title' => Yii::t('app', 'View'),
//                                    'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
//                            //update button
//                            'update' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>更新', $url, [
//                                    'title' => Yii::t('app', 'Update'),
//                                    'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
//                            //update button
//                            'delete' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>删除', $url, [
//                                    'title' => Yii::t('app', 'Delete'),
//                                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
//                                    'data-method' => 'post',
//                                    'data-pjax' => '0',
//                                    'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
//                        ],
//            ],
            [
                'label' => '操作',
                'format' => 'raw',
                'value' => function($model) {
                   return Html::Button('菜单', ['onclick'=>'btncaidan()','agentid' => $model->agentid, 'qyhid' =>$model->qid, 'name'=>$model->id,'class'=>'btn btn-default','title' => '菜单','id'=>'modalButton','data-toggle'=>'modal', 'data-target'=>'#modal']);
                }
            ]
        ],
    ]);
    ?>
    <?php Pjax::end(); ?>
    
</div>

<?php
                yii\bootstrap\Modal::begin([
                    'header' => '菜单编辑器',
                    'id' => 'modal',
                    'size' => 'modal-lg',
                ]);
                ?>   
                <?php
                echo $this->render('popWindow', ['model' => new app\models\GkyWeMenu()]);
                ?>
                <?php yii\bootstrap\Modal::end() ?>


<script type="text/javascript">
    //控制导航菜单的开关
    function btncaidan() {
        if ($("#caidan", window.parent.document))
        {
            $("#caidan", window.parent.document).removeClass("funcmenu_switcher");
            $("#caidan", window.parent.document).addClass("funcmenu_switcher active");
            $("#body", window.parent.document).removeClass("TOS");
            $("#body", window.parent.document).addClass("TOS open-menu");
        }
    }

    $(".close").click(function () {
        $("#caidan", window.parent.document).removeClass("funcmenu_switcher active");
        $("#caidan", window.parent.document).addClass("funcmenu_switcher");
        $("#body", window.parent.document).removeClass("TOS open-menu");
        $("#body", window.parent.document).addClass("TOS");
    });
</script>
